﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KeyTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        const int _groupTimeSpan = 500;

        private DateTime _lastKeyDownTime;
        private ListViewGroup _lastGroup;

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if ((DateTime.Now - _lastKeyDownTime).TotalMilliseconds > _groupTimeSpan)
            {
                _lastGroup = new ListViewGroup(DateTime.Now.ToString());
                listView1.Groups.Add(_lastGroup);
            }

            _lastKeyDownTime = DateTime.Now;

            var item = new ListViewItem(new []{
                e.Alt.ToString(),
                e.Control.ToString(),
                e.Shift.ToString(),
                e.Modifiers.ToString(),
                e.KeyCode.ToString(),
                e.KeyData.ToString(),
                e.KeyValue.ToString(),
                e.SuppressKeyPress.ToString(),
            });
            item.Selected = true;
            item.Group = _lastGroup;
            listView1.Items.Add(item);
            listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            listView1.Items.Clear();
        }
    }
}
